﻿#ifndef __SS_DB_THREAD_INTERFACE_H__
#define __SS_DB_THREAD_INTERFACE_H__
#include "thread/ssMsgThread.h"
#include "message/ssNetMsgHead.h"
#include "ssMySQLStmtQuery.h"

#define SS_DBEV_CLEAR_BUFFER	0xfffffff1
#define SS_DBEV_QUERY_INFO		0xfffffff2

namespace StarSeeker
{

class ssDBThreadBase : public StarSeeker::ssMsgThread
{
public:
	ssDBThreadBase();
	~ssDBThreadBase();
	//初始化连接
	bool Init(const char *pIP, u32	port, const char *pAccount, const char *pPW, const char *pDBName);
protected:
	//查询路由，由子类实现
	virtual bool OnDBMsg(ssNetMsgHead* pHead, const char* pData, const u32 dataLen, u32 connectID) = 0;
	//发送查询回包
	virtual void SendResponse(u32 connectID, ssNetMsgHead* pHead, char* pData, u32 len) = 0;
	//执行查询的函数
	bool OnDBMsgNullRecord(u32 id, ssNetMsgHead* pHead, const char* pData, const u32 dataLen, u32 connectID);
	bool OnDBMsgOneRecord(u32 id, ssNetMsgHead* pHead, const char* pData, const u32 dataLen, u32 connectID);
	bool OnDBMsgMultiRecord(u32 id, ssNetMsgHead* pHead, const char* pData, const u32 dataLen, u32 connectID);
	void OnDBMsgCleanBuffer();
	//处理非网络消息
	virtual bool OnOtherMsg(ssMsg_s &m);
private:
	//消息处理
	void HandleMessage(ssMsg_s &m);

protected:
	ssMySQLStmtQuery		m_mysqlQuery;
public:
	bool					m_queryLog;
};

}
#endif
